home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_7 / aquad.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  851 b   |  23 lines  |  [MATF/MATL]

  1. function [quad,errb,cnt] = aquad(f,a,b,tol)
  2. % [quad,errb,cnt] = aquad(f,a,b,tol)
  3. % Adaptive Quadrature using Simpson`s rule.
  4. % f is the name of the function, input.
  5. % a is the left  endpoint, input.
  6. % b is the right endpoint, input.
  7. % tol is the tolerance, input.
  8. % quad is the quadrature value, output.
  9. % err is the error estimate, output.
  10. % cnt is the number of function evaluations, output.
  11. % lev keeps track of the level of recursion, program variable.
  12. c = (a + b)/2;         % Starting initialization
  13. fa = feval(f,a);       % which is required before
  14. fb = feval(f,b);       % recursively calling the
  15. fc = feval(f,c);       % subroutine  Aquadstep.
  16. lev = 1;
  17. sr0 = inf;
  18. errb = 0;
  19. % Now perform adaptive quadrature by recursive
  20. % programming and using the subroutine  aqustep.
  21. [quad,errb,cnt] = aqustep(f,a,c,b,fa,fc,fb,sr0,tol,lev);
  22. cnt = cnt + 3;
  23.